home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Applications / QuArK / plugins / mapaxisicons.py < prev    next >
Text File  |  2004-01-05  |  5KB  |  150 lines

  1.  
  2. Info = {
  3.    "plug-in":       "Display axis icons",
  4.    "desc":          "Displays the axis icons in the viewing windows",
  5.    "date":          "June 14 2002",
  6.    "author":        "cdunde",
  7.    "author e-mail": "cdunde1@attbi.com",
  8.    "quark":         "Version 6" }
  9.  
  10.  
  11. import quarkx
  12. import quarkpy.mapoptions
  13. from quarkpy.maputils import *
  14. from quarkpy.qhandles import *
  15.  
  16.  
  17. #
  18. # <tiglari>
  19. #
  20. # This snippet redefines the MakeScroller function in the qhandles
  21. #  module, eliminating the need for a new qhandles.py file.
  22. #
  23.  
  24.  
  25.  
  26. #
  27. # This attaches the item to the options menu; it's best for new
  28. #  facilities to redefine menus etc in the quarkpy modules rather
  29. #  than modify the files themselves because then if people don't
  30. #  like the effects of your plugin they can remove all of them by
  31. #  deleting one file.  The toggle-item itself works fine.
  32. # The prolixity of `quarkpy.mapoptions' could be reduced by using
  33. #  `import X from mapoptions' statements (without ""'s & #)as follows:
  34. #""from quarkpy.mapoptions import *"" and
  35. #""items.append(toggleitem("&Axis XYZ letter indicator in view windows",
  36. #"AxisXYZ", (1,1),
  37. #      hint="|Display the X Y or Z indicator letter per view to associate #the rotation menu buttons. These are for reference only and are not #selectable with the mouse."))""
  38.  
  39. # But I don't think that would be worthwhile, 
  40. #  so we'll just use the long version below insted:
  41. #
  42.  
  43. quarkpy.mapoptions.items.append(quarkpy.mapoptions.toggleitem("&Axis XYZ letter indicator in view windows", "AxisXYZ", (1,1),
  44.       hint="|Axis XYZ letter indicator in view windows:\n\nThis display s the X Y or Z indicator letter per view to associate the rotation menu buttons. These are for reference only and are not selectable with the mouse.|intro.mapeditor.menu.html#optionsmenu"))
  45.  
  46. #
  47. # Get the actual icons, no reason to do this more than once.
  48. # Done by the loadimages function and the required augments.
  49. #  img = quarkx.loadimages(filename + ext, width, transparencypt)
  50. #
  51.  
  52. axisicons = quarkx.loadimages("images\\axisicons.bmp",32,(0,0))
  53.  
  54. #
  55. # This part is a magical incantation.
  56. # First the normal arguments for
  57. #  finishdrawing, then the oldfinish=... stuff,
  58. #  which has the effect of storing the current
  59. #  finishdrawing method inside this function as
  60. #  the value of the oldfinish variable.
  61. # These def statements are executed as the plugins are being
  62. #  loaded, but not reexecuted in later operations
  63. #  of the map editor, only the functions they define are.
  64. #
  65.  
  66. def newfinishdrawing(editor, view, oldfinish=quarkpy.qbaseeditor.BaseEditor.finishdrawing):
  67.  
  68.     #
  69.     # execute the old method
  70.     #
  71.  
  72.     oldfinish(editor, view)
  73.  
  74.     #
  75.     # Why not see what the clientarea produces.
  76.     # Look at the console to find out.
  77.     #
  78. #    debug('area: '+`view.clientarea`)
  79.  
  80.     #
  81.     # Below ties this function to the toggel button
  82.     #  in the Option menu.
  83.     #
  84.  
  85.     if not MapOption("AxisXYZ"):return
  86.  
  87.     import quarkpy.qhandles
  88.     def MyMakeScroller(layout, view):
  89.         sbviews = [None, None]
  90.         for ifrom, linkfrom, ito, linkto in layout.sblinks:
  91.             if linkto is view:
  92.                 sbviews[ito] = (ifrom, linkfrom)
  93.         def scroller(x, y, view=view, hlink=sbviews[0], vlink=sbviews[1]):
  94.             view.scrollto(x, y)
  95.             if hlink is not None:
  96.                 if hlink[0]:
  97.                     hlink[1].scrollto(None, x)
  98.                 else:
  99.                     hlink[1].scrollto(x, None)
  100.             if vlink is not None:
  101.                 if vlink[0]:
  102.                     vlink[1].scrollto(None, y)
  103.                 else:
  104.                     vlink[1].scrollto(y, None)
  105.             if not MapOption("AxisXYZ"):
  106.                 view.update()
  107.             else:
  108.                 view.repaint()
  109.         return scroller
  110.     quarkpy.qhandles.MakeScroller = MyMakeScroller
  111.  
  112.  
  113.  
  114.  
  115.  
  116.     # The following sets the canvas function to draw the images.
  117.  
  118.     cv = view.canvas()
  119.     type = view.info["type"]  # These type values are set
  120.                               #  in the layout-defining plugins.
  121.     if type == "YZ":
  122.        index = 0
  123.     elif type == "XZ":
  124.        index = 1
  125.     elif type == "XY":
  126.        index = 2
  127.     else:
  128.        return
  129.  
  130.     #
  131.     # ahah, the canvas has absolute coordinates with relation
  132.     #  to the window it appears in.
  133.     #
  134.  
  135.     cv.draw(axisicons[index],14,1)
  136.  
  137. #
  138. # Now set our new function as the finishdrawing method.
  139. #
  140.  
  141.  
  142. quarkpy.qbaseeditor.BaseEditor.finishdrawing = newfinishdrawing
  143.     
  144. #
  145. # There is still the problem that when the view is panned, the old image is not erased, we
  146. #   need to find out how the red lines are drawn, and how grey-out-of-view really works,
  147. #   to learn how to stop this.  The images persist only in the view that's actually being
  148. #   dragged on, but flicker in the others, which looks unprofessional, whereas the
  149. #   red line is rock solid.
  150. #